import service from '@/request/index.js'
import { getTimeStamp } from '@/tool/index.js'

/*  首页 */

/*
 * @description: 获取定位城市
 * @param {type}
 * @return:
 */

export const fetchLocation = () => {
  return service.get(`/showapi/site_city?time=${getTimeStamp()}`, {
    apiName: '获取定位城市',
  })
}

/*
 * @description: 获取城市列表
 * @param {type}
 * @return:
 */

export const fetchCityList = () => {
  return service.get(`/showapi/cities?time=${getTimeStamp()}`, {
    apiName: '获取城市列表',
  })
}

/*
 * @description: 获取弹窗广告和服条款
 * @param {type}
 */

export const fetchPopUpAd = (siteOID, siteCityOID) => {
  // return service.get(`/showapi/pub/site/${siteOID}/banner/app?siteCityOID=${siteCityOID}&siteOID=${siteOID}&version=V2&time=${getTimeStamp()}`)
  return service.get(
    `/showapi/pub/site/${siteOID}/banner/app?siteCityOID=${siteCityOID}&siteOID=${siteOID}&version=V2&time=${getTimeStamp()}`,
    {
      apiName: '获取弹窗广告和服条款',
    },
  )
}

/*
 * @description: 首页搜索推荐词
 * @param {type}
 */
export const fetchSearchHot = (cityId) => {
  return service.get(`/userdataapi/pub/v1/top/keywords?cityId=${cityId}&time=${getTimeStamp()}`, {
    apiName: '首页搜索推荐词',
  })
}

/*
 * @description: 首页大部分内容 顶部分类 +Banner+热门巡演 + 折扣尾票
 * @param {type}
 */
export const fetchHomeData = (cityId) => {
  return service.get(
    `/mtl_recommendapi/pub/home/v1/static_floor?cityId=${cityId}&time=${getTimeStamp()}`,
    {
      apiName: '首页大部分内容 顶部分类 +Banner+热门巡演 + 折扣尾票',
    },
  )
}

/*
 * @description: 首页 为你推荐
 * @param {type}
 */
export const fetchHomeRecommend = (cityId, length = 20, offset = 0) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v1/hot_show?time=${getTimeStamp()}`,
    {
      cityId,
      siteCityOID: cityId,
      length,
      offset,
    },
    {
      apiName: '首页 为你推荐',
    },
  )
}

/*  分类页  */

/*
 * @description: 分类页 获取分类列表
 * @param {type}
 */
export const fetchCategoryList = (cityId) => {
  return service.post(
    `/mtl_recommendapi/pub/show/v2/find_show_type?time=${getTimeStamp()}`,
    {
      cityId,
    },
    {
      apiName: '分类页 获取分类列表',
    },
  )
}

/*
 * @description: 演出城市筛选
 * @param {type}
 */
export const fetchShowCity = (cityId) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v1/find_city_list?time=${getTimeStamp()}`,
    {
      cityId,
    },
    {
      apiName: '演出城市筛选',
    },
  )
}

/*
 * @description: 获取演出筛选tag
 * @param {type}
 */
export const fetchShowFilterTag = (
  cityId,
  showType = 'All',
  showCityList = null,
  beginDateTime = null,
  endDateTime = null,
) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v1/find_tag_list?time=${getTimeStamp()}`,
    {
      cityId,
      showType,
      showCityList,
      beginDateTime,
      endDateTime,
    },
    {
      apiName: '获取演出筛选tag',
    },
  )
}

/*
 * @description: 演出列表查询
 * @param {type}
 */
export const fetchShowList = (
  cityId,
  showType,
  showCityList,
  beginDateTime,
  endDateTime,
  sorting,
  length,
  offset,
  tagId,
) => {
  // 构造请求参数对象
  const requestParams = {
    cityId,
    showType,
    showCityList,
    beginDateTime,
    endDateTime,
    sorting,
    length,
    offset,
  }

  // 只有当 tagId 有值时才添加到参数中
  if (tagId !== undefined && tagId !== null && tagId !== '') {
    requestParams.tagId = tagId
  }

  return service.post(
    `/mtl_recommendapi/pub/search/v1/find_show_list?time=${getTimeStamp()}`,
    requestParams,
    {
      apiName: '演出列表查询',
    },
  )
}

/*
 * @description: 搜索页
 * @param {type}
 */
// 热门搜索
export const fetchHotSearch = (cityId) => {
  return service.get(`/buyerapi/buyer/v1/search/index?cityId=${cityId}&time=${getTimeStamp()}`, {
    apiName: '搜索页 热门搜索',
  })
}

// 搜索推荐列表
export const fetchSearchHint = (cityId, keyword) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v3/search/keywords/hints?time=${getTimeStamp()}`,
    {
      cityId,
      keyword,
    },
    {
      apiName: '搜索推荐列表',
    },
  )
}

//搜索结果列表页
export const fetchSearchList = (cityId, keyword, length, offset) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v3/search?time=${getTimeStamp()}`,
    {
      cityId,
      keyword,
      length,
      offset,
    },
    {
      apiName: '搜索结果列表页',
    },
  )
}

/*
 * @description: 巡演简介
 * @param {type}
 */
export const fetchTourDetail = (tagId) => {
  return service.get(
    `/mtl_recommendapi/pub/star_tour/v1/find_detail?tagId=${tagId}&time=${getTimeStamp()}`,
    {
      apiName: '巡演简介',
    },
  )
}

/*
 * @description: 巡演站点列表
 * @param {type}
 */
export const fetchTourSiteList = (cityId, tagId) => {
  return service.get(
    `/mtl_recommendapi/pub/star_tour/v1/find_show_list?cityId=${cityId}&tagId=${tagId}&time=${getTimeStamp()}`,
    {
      apiName: '巡演站点列表',
    },
  )
}

/*
 * @description: 全部巡演列表
 * @param {type}
 */
export const fetchTourList = (cityId, length, offset) => {
  return service.get(
    `/mtl_recommendapi/pub/star_tour/v1/find_list?cityId=${cityId}&length=${length}&offset=${offset}&time=${getTimeStamp()}`,
    {
      apiName: '全部巡演列表',
    },
  )
}

/*
 * @description: 巡演站点详情
 * @param {type}
 */
export const fetchTourSiteDetail = (showId, locationCityOID) => {
  return service.get(
    `/showapi/pub/show/${showId}?locationCityOID=${locationCityOID}&ver=6.48.3&time=${getTimeStamp()}`,
    {
      apiName: '巡演站点详情',
    },
  )
}
/*
 * @description: 巡演站点详情 - 站点列表
 * @param {type}
 */
export const fetchTourSites = (showId) => {
  return service.get(
    `/mtl_recommendapi/pub/star_tour/v1/find_show_list_by_show_id?showId=${showId}&time=${getTimeStamp()}`,
    {
      apiName: '巡演站点详情 - 站点列表',
    },
  )
}

/*
 * @description: 巡演站点详情 - 退票规则
 * @param {type}
 */
export const fetchTourSiteRefundRule = (showId) => {
  return service.get(`/showapi/pub/v1/show_ap_rules/${showId}?time=${getTimeStamp()}`, {
    apiName: '巡演站点详情 - 退票规则',
  })
}

/*
 * @description: 巡演站点详情 - 服务说明和观演须知
 * @param {type}
 */
export const fetchTourSiteService = (showOID) => {
  return service.post(
    `/showapi/pub/show/v1/get_service_notes?time=${getTimeStamp()}`,
    { showOID },
    {
      apiName: '巡演站点详情 - 服务说明和观演须知',
    },
  )
}

/*
 * @description: 巡演站点详情页-常见问题
 * @param {type}
 */
export const fetchTourSiteFaq = (showId) => {
  return service.get(
    `/showapi/pub/v1/shows/${showId}/faq_tags?type=SHOW_FAQ&time=${getTimeStamp()}`,
    {
      apiName: '巡演站点详情 - 常见问题',
    },
  )
}

/*
 * @description: 巡演站点详情 - 为你推荐
 * @param {type}
 */
export const fetchTourSiteRecommend = (cityId, showId, length, offset) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v1/hot_show?time=${getTimeStamp()}`,
    {
      cityId,
      showId,
      length,
      offset,
    },
    {
      apiName: '巡演站点详情 - 为你推荐',
    },
  )
}

/*
 * @description: 巡演站点详情 - 购买演出参数
 * @param {type}
 */
export const fetchTourSitePurchaseParams = (showId, locationCityOID) => {
  return service.get(
    `/showapi/pub/v3/show/${showId}/sessionone?locationCityOID=${locationCityOID}&orderDecision=RANDOM&time=${getTimeStamp()}`,
    {
      apiName: '巡演站点详情 - 购买演出参数',
    },
  )
}

/*
 * @description: 巡演购票 - 场次座位数量
 * @param {type}
 */
export const fetchTourSiteSessionSeatCount = (sessionId) => {
  return service.post(
    `/showapi/pub/show_session/v1/find_sale_ticket_number?time=${getTimeStamp()}`,
    { id: sessionId },
    {
      apiName: '巡演购票 - 场次座位数量',
    },
  )
}

/*
 * @description: 巡演购票 - 场馆详情图
 * @param {type}
 */
export const fetchTourSiteVenueDetail = (sessionId) => {
  return service.post(
    `/showapi/pub/show_session/v1/find_seat_picking_setting?time=${getTimeStamp()}`,
    {
      id: sessionId,
    },
    {
      apiName: '巡演购票 - 场馆详情图',
    },
  )
}
/*
 * @description: 巡演购票 - 票面选座
 * @param {type}
 */
export const fetchTourSiteTicketSeat = (locationCityOID, showSessionId, ticketNumber) => {
  return service.post(
    `/showapi/pub/show_sessions/v2/find_seat_plans?time=${getTimeStamp()}`,
    {
      locationCityOID,
      showSessionId,
      ticketNumber,
    },
    {
      apiName: '巡演购票 - 票面选座',
    },
  )
}

/*
 * @description: 巡演购票 - 门票筛选
 * @param {type}
 */
export const fetchTourSiteTicketFilter = (
  showSessionId,
  adjacentSeat,
  length,
  locationCityOID,
  offset,
  seatPlanId,
  ticketNumber,
  ticketSortType,
  zoneIdList,
) => {
  return service.post(
    `/showapi/pub/show_session/v1/find_tickets?time=${getTimeStamp()}&ver=6.48.5&src=m_web`,
    {
      showSessionId,
      adjacentSeat,
      length,
      locationCityOID,
      offset,
      seatPlanId,
      ticketNumber,
      ticketSortType,
      zoneIdList,
      ver: '6.48.5',
      time: getTimeStamp().toString(),
      src: 'm_web',
    },
    {
      apiName: '巡演购票 - 门票筛选',
    },
  )
}

/*
 * @description: 转票 - 近期转票
 * @param {type}
 */
export const fetchTourSiteTicketTransfer = (siteCityOID, length, offset) => {
  return service.get(
    `/showapi/site/1001/transfer/recentShows?bizCode=MTL&isSupportSession=true&length=${length}&offset=${offset}&siteCityOID=${siteCityOID}&time=${getTimeStamp()}`,
    {
      apiName: '转票 - 近期转票',
    },
  )
}

/*
 * @description: 转票 - 选场次 和 出票方式
 * @param {type}
 */
export const fetchTourSiteTicketTransferSession = (showId) => {
  return service.get(`/showapi/transfer/show/${showId}/session?time=${getTimeStamp()}`, {
    apiName: '转票 - 选场次 和 出票方式',
  })
}

/*
 * @description: 转票 - 选票面座位
 * @param {type}
 */
export const fetchTourSiteTicketTransferSeat = (showSessionID) => {
  return service.get(
    `/showapi/transfer/show/session/${showSessionID}/seatPlan?sessionId=${showSessionID}`,
    {
      apiName: '转票 - 选票面座位',
    },
  )
}

/*
 * @description: 转票 - 搜索演出转票
 * @param {type}
 */
export const fetchTourSiteTicketTransferSearch = (cityId, keyword, length, offset) => {
  return service.post(
    `/mtl_recommendapi/pub/search/v1/transfer_show?time=${getTimeStamp()}`,
    { cityId, keyword, length, offset },
    {
      apiName: '转票 - 搜索演出转票',
    },
  )
}
